import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 * @description:
 * @title: BlockingDemo
 * @author: zp
 * @date: 2021/8/1 18:14
 * 1、队列
 * 2、阻塞队列
 *  2.1 阻塞队列的好处
 *  2.2 不得不阻塞你怎么管理
 */
public class BlockingDemo {
    public static void main(String[] args) throws InterruptedException {
        //BlockingQueue<String> arrayBlockingQueue=new ArrayBlockingQueue<>(3);
        //arrayBlockingQueue.put("123");
        //arrayBlockingQueue.put("13");
        //arrayBlockingQueue.put("12");
        //System.out.println("=======================");
        //System.out.println(arrayBlockingQueue.take());
        //arrayBlockingQueue.put("000");
        BlockingQueue<String> arrayBlockingQueue=new SynchronousQueue<>();
        new Thread(()->{
            try {
                arrayBlockingQueue.put("a");
                System.out.println("取出");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"aa").start();

        new Thread(()->{
            try {
                arrayBlockingQueue.take();
                System.out.println("拿出");
            } catch (Exception e) {
                e.printStackTrace();
            }
        },"bb").start();

        System.out.println("成功");

    }
}
